<%namespace name="admin_include" file="/admin/base/include.html" />
<%inherit file="/front/base/businessbase.html"/>
<%def name="script()">
${admin_include.jqxgrid()}
</%def>
<%def name="center()">
<div class="row">
    <h3 class="lit page-header no-margin" style="margin-bottom:10px;">优惠券列表</h3>
    <p class="pull-right">
        <button class="btn btn-primary" type="button" id="addnew">新增</button>
    </p>
    %if info:
    <div class="alert alert-success"><strong>${info}</strong></div>
    %endif
    <div id="jqxgrid">
    </div>
</div>
<script type="text/javascript">
var imagerenderer= function (row, columnfield, value, defaulthtml, columnproperties) {
    return '<img style="margin-left: 5px;" height="90" width="130" src="' + value + '"/>';
}

var titlerenderer= function (row, columnfield, value, defaulthtml, columnproperties) {
    return '<div class ="var" style="text-align: center; font-weight:bold; margin-top: 5px; height:60px; line-height:60px;">'+ value + '</div>';
}

var cellsrenderer = function (row, column, value) {
    return '<div style="text-align: center; margin-top: 5px; height: 60px; line-height: 60px;">' + value + '</div>';
}

var columnsrenderer = function (value) {
    return '<div style="text-align: center; margin-top: 5px;"><strong>' + value + '</strong></div>';
}

var actionrenderer = function (row, column, value) {
    return '<div style="text-align: center; margin-top: 5px; height: 60px; line-height: 60px;"><a href="./couponpublish/'+value+'.html">编辑</a>&nbsp;<a href="./deletecoupon/'+value+'.html">删除</a></div>';
}

$(document).ready(function () {
    var gridSetting = new Array(
        {name: 'picture', datafield:'picture', text:'图片', width:130, cellsrenderer: imagerenderer, renderer:columnsrenderer},
        {name: 'name', datafield:'name', text:'名称', width:120, cellsrenderer: titlerenderer, renderer:columnsrenderer},
        {name: 'coupontype', datafield:'coupontype', text: '类型', width:90, cellsrenderer: cellsrenderer, renderer:columnsrenderer},
        {name: 'startdate', datafield:'startdate', text: '开始时间', width:75, cellsrenderer: cellsrenderer, renderer:columnsrenderer},
        {name: 'enddate', datafield:'enddate', text: '结束时间', width:75, cellsrenderer: cellsrenderer, renderer:columnsrenderer},
        {name: 'number', datafield:'number', text: '数量', width:45, cellsrenderer: cellsrenderer, renderer:columnsrenderer},
        {name: 'getnumber', datafield:'getnumber', text: '领取', width:50, cellsrenderer: cellsrenderer, renderer:columnsrenderer},
        {name: 'status', datafield:'status', text: '状态', width:50, cellsrenderer: cellsrenderer, renderer:columnsrenderer},
        {name: 'id', datafield:'id', text: '操作', width:65, cellsrenderer: actionrenderer, renderer:columnsrenderer}
    );

    //to get the theme
    var theme = getTheme();

    // prepare the data
    var source =
    {
        datatype: "json",
        datafields: gridSetting,
        pagesize: 5,
        url:'./api_allcoupons.html',
        root: 'Rows',
        beforeprocessing: function(data){
            source.totalrecords = data.TotalRows;
        },
    };

    var dataAdapter = new $.jqx.dataAdapter(source);

    // initialize jqxGrid
    $("#jqxgrid").jqxGrid(
    {
        width: 700,
        rowsheight: 60,
        height: 450,
        source: dataAdapter,
        theme: theme,
        pageable: true,
        autoheight: true,
        altrows: true,
        virtualmode: true,
        columnsresize: true,
        rendergridrows: function(){
            return this.source.records;
        },
        columns: gridSetting
    });

   $("#jqxgrid").bind('bindingcomplete', function () {
        var localizationobj = {};
        localizationobj.pagergotopagestring = "跳转到:";
        localizationobj.pagershowrowsstring = "当前:";
        localizationobj.pagerrangestring = " 共 ";
        localizationobj.pagernextbuttonstring = "voriger";
        localizationobj.pagerpreviousbuttonstring = "nächster";
        localizationobj.sortascendingstring = "Sortiere aufsteigend";
        localizationobj.sortdescendingstring = "Sortiere absteigend";
        localizationobj.sortremovestring = "Entferne Sortierung";

        // apply localization.
        $("#jqxgrid").jqxGrid('localizestrings', localizationobj);
    });

   $('#addnew').click(function(){
        window.location = '/business/couponpublish.html';
    });
});
</script>
</%def>
